//
//  CHPraiseComment.m
//  ChildHoodStemp
//
//  Created by zhuxuehang on 13-10-21.
//
//

#import "CHPraiseComment.h"
#import <QuartzCore/QuartzCore.h>
//static CHPraiseComment* shared;
@implementation CHPraiseComment
@synthesize chDelegate = _chDelegate;

//+(CHPraiseComment*)defaultFrame:(CGRect)frame delegate:(id)delegateTmp
//{
//    @synchronized(self)
//    {
//        if(shared == nil)
//        {
//            shared = [[CHPraiseComment alloc] initWithFrame:frame];
//            shared.chDelegate = delegateTmp;
//        }
//    }
//    return shared;
//}
//-(id)initWithFrame:(CGRect)frame delegate:(id)delegateTmp
//{
//    if (self = [super initWithFrame:frame]) {
////        [self initWithFrame:frame];
//        self.chDelegate = delegateTmp;
//    }
//    return self;
//}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        CGRect fra = frame;
        fra.size.width = PCCViewWidth;
        fra.size.height = PCCViewHeight;
        [self setFrame:fra];
        UIImage* img = [UIImage imageNamed:@"parentchildroom_showpcc_bg.png"];
        img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10) resizingMode:UIImageResizingModeStretch];
        UIImageView* imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, PCCViewWidth, PCCViewHeight)];
        [imgView setImage:img];
        [self addSubview:imgView];        
        [self initData];
        [self.layer setCornerRadius:10];
        [self setClipsToBounds:YES];
    }
    return self;
}

-(void)initData
{
    
    UIButton* praiseBtn = [self buttonWithFrame:CGRectMake(5, 5, 40, 35)
                                    normalTitle:@"赞"
                                  selectedTitle:@"取消赞"
                                         norImg:[UIImage imageNamed:@"parentchildroom_showpcc_xin"]
                                         selImg:nil
                                            tag:101
                                         action:@selector(praiseBtnMethod:)
                                   cornerRadius:5];
    [self addSubview:praiseBtn];
    
    UIButton* commentBtn = [self buttonWithFrame:CGRectMake(50, 5, 60, 35)
                                     normalTitle:@"评论"
                                   selectedTitle:nil
                                          norImg:[UIImage imageNamed:@"parentchildroom_showpcc_pinglun"]
                                          selImg:nil
                                             tag:102
                                          action:@selector(commentBtnMethod:)
                                    cornerRadius:5];
    [self addSubview:commentBtn];
    
    UIButton* clectionBtn = [self buttonWithFrame:CGRectMake(115, 5, 60, 35)
                                     normalTitle:@"收藏"
                                   selectedTitle:nil
                                          norImg:[UIImage imageNamed:@"parentchildroom_showpcc_shoucang"]
                                          selImg:nil
                                             tag:103
                                          action:@selector(clectionBtnMethod:)
                                    cornerRadius:5];
    [self addSubview:clectionBtn];
}

-(UIButton*)buttonWithFrame:(CGRect)frame normalTitle:(NSString*)nortitle selectedTitle:(NSString*)selTitle norImg:(UIImage*)norImg selImg:(UIImage*)selImg tag:(NSInteger)tagNum action:(SEL)action cornerRadius:(CGFloat)radius
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:frame];
    [btn setTitle:nortitle forState:UIControlStateNormal];
    [btn setTitle:selTitle forState:UIControlStateSelected];
    [btn setImage:norImg forState:UIControlStateNormal];
    [btn setImage:selImg forState:UIControlStateSelected];
    [btn setTag:tagNum];
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    return  btn;
}

-(void)praiseBtnMethod:(id)sender
{
    NSLog(@"####################### zan");
    if (_chDelegate && [_chDelegate respondsToSelector:@selector(praiseBtnClick:)]) {
        [self.chDelegate praiseBtnClick:sender];
    }
}

-(void)commentBtnMethod:(id)sender
{
    NSLog(@"####################### pinglun ");
    if (_chDelegate && [_chDelegate respondsToSelector:@selector(commentBtnClick:)]) {
        [self.chDelegate commentBtnClick:sender];
    }
}

-(void)clectionBtnMethod:(id)sender
{
    NSLog(@"####################### shoucang ");
    if (_chDelegate && [_chDelegate respondsToSelector:@selector(clectionBtnClick:)]) {
        [self.chDelegate clectionBtnClick:sender];
    }
}

@end
